package com.shycloud.mido.member.controller;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import com.shycloud.mido.common.core.util.R;
import com.shycloud.mido.common.security.util.SecurityUtils;
import com.shycloud.mido.member.api.entity.BasicShoppingBanner;
import com.shycloud.mido.member.api.vo.AppAppShoppingCartVO;
import com.shycloud.mido.member.api.vo.AppShoppingOrderVO;
import com.shycloud.mido.member.api.vo.AppShoppingPurchaseVO;
import com.shycloud.mido.member.service.AppShoppingMallService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import springfox.documentation.annotations.ApiIgnore;

/**
 * @author Xiaoxing Yu
 * @date 1/29/21 11:22 AM
 **/
@ApiIgnore
@Api(value = "App商城接口", tags = "App商城接口")
@RestController
@AllArgsConstructor
@RequestMapping("/appShopping")
public class AppShoppingMallController {

	private AppShoppingMallService shoppingMallService;

	/**
	 * 获取所有商品列表
	 *
	 * @param
	 * @return com.shycloud.mido.common.core.util.R
	 * @author xiaoxing.yu
	 * @date 1/29/21 11:28 AM
	 */
	@GetMapping("getAllGoods")
	@ApiOperation("获取所有商品列表")
	public R getEditableGoods() {
		return new R(shoppingMallService.getAllGoods());
	}

	/**
	 * 搜索商品
	 *
	 * @param keyword
	 * @return com.shycloud.mido.common.core.util.R
	 * @author xiaoxing.yu
	 * @date 2/24/21 5:31 PM
	 */
	@GetMapping("searchGoods")
	@ApiOperation("搜索商品")
	public R searchGoods(String keyword) {
		return new R(shoppingMallService.searchGoods(keyword));
	}

	/**
	 * 加入到购物车
	 *
	 * @param appShoppingCartVO
	 * @return com.shycloud.mido.common.core.util.R
	 * @author xiaoxing.yu
	 * @date 1/29/21 12:41 PM
	 */
	@PostMapping("addToCart")
	@ApiOperation("加入到购物车")
	public R addToCart(@RequestBody AppAppShoppingCartVO appShoppingCartVO) {
		return new R(shoppingMallService.addToCart(appShoppingCartVO));
	}

	/**
	 * 批量删除购物车
	 *
	 * @param idList
	 * @return com.shycloud.mido.common.core.util.R
	 * @author xiaoxing.yu
	 * @date 2/22/21 9:10 AM
	 */
	@PostMapping("deleteCart")
	@ApiOperation("批量删除购物车")
	public R deleteCart(@RequestBody List<Integer> idList) {
		return new R(shoppingMallService.deleteCart(idList));
	}

	/**
	 * 获取购物车商品
	 *
	 * @param
	 * @return com.shycloud.mido.common.core.util.R
	 * @author xiaoxing.yu
	 * @date 2/1/21 1:44 PM
	 */
	@GetMapping("getShoppingCart")
	@ApiOperation("获取购物车商品")
	public R getShoppingCart() {
		return new R(shoppingMallService.getShoppingCart());
	}

	@GetMapping("getCartByCollection")
	@ApiOperation("根据曲集ID获取购物车商品")
	public R getCartByCollection(String memberId, Integer collectionId) {
		return new R(shoppingMallService.getCartByCollection(memberId, collectionId));
	}

	/**
	 * 批量编辑购物车(之后版本可能有) TODO
	 *
	 * @param appShoppingCartVO
	 * @return com.shycloud.mido.common.core.util.R
	 * @author xiaoxing.yu
	 * @date 2/22/21 9:10 AM
	 */
	@PostMapping("editCart")
	@ApiOperation("批量编辑购物车")
	public R editCart(@RequestBody AppAppShoppingCartVO appShoppingCartVO) {
		return new R(shoppingMallService.editCart(appShoppingCartVO));
	}

	/**
	 * 创建一个APP商城订单
	 *
	 * @param orderVO
	 * @return com.shycloud.mido.common.core.util.R
	 * @author xiaoxing.yu
	 * @date 1/29/21 1:19 PM
	 */
	@PostMapping("createOrder")
	@ApiOperation("创建一个订单")
	public R createOrder(@RequestBody AppShoppingOrderVO orderVO) throws Exception {
		return new R(shoppingMallService.createOrder(orderVO));
	}

	/**
	 * 搜索订单
	 *
	 * @param keyword
	 * @return com.shycloud.mido.common.core.util.R
	 * @author xiaoxing.yu
	 * @date 2/22/21 9:27 AM
	 */
	@GetMapping("searchOrder")
	@ApiOperation("搜索订单")
	public R searchOrder(String keyword) {
		return new R(shoppingMallService.searchOrder(keyword));
	}

	/**
	 * 获取所有历史订单
	 *
	 * @param
	 * @return com.shycloud.mido.common.core.util.R
	 * @author xiaoxing.yu
	 * @date 2/22/21 1:09 PM
	 */
	@GetMapping("getOrders")
	@ApiOperation("获取所有历史订单")
	public R getOrders(String status) {
		return new R(shoppingMallService.getOrders(status));
	}

	/**
	 * 使用快乐贝购买
	 *
	 * @param purchaseVO
	 * @return
	 */
	@PostMapping("purchase")
	@ApiOperation("使用快乐贝购买")
	public R purchase(@RequestBody AppShoppingPurchaseVO purchaseVO) {
		return shoppingMallService.purchase(purchaseVO);
	}

	/**
	 * 获取用户快乐贝和积分
	 *
	 * @return com.shycloud.mido.common.core.util.R
	 * @author xiaoxing.yu
	 * @date 2/24/21 5:31 PM
	 */
	@GetMapping("getUserAvail")
	@ApiOperation("获取用户快乐贝和积分")
	public R getUserAvail() {
		return new R(shoppingMallService.getUserAvail(SecurityUtils.getMember().getId()));
	}

	/**
	 * 获取Banners
	 *
	 * @return com.shycloud.mido.common.core.util.R
	 * @author xiaoxing.yu
	 * @date 3/5/21 9:29 AM
	 */
	@GetMapping("getBanners")
	@ApiOperation(value = "Banner管理 - 获取 banner 信息", tags = "后台商城 banner 设置接口")
	@ApiOperationSupport(order = 1)
	public R<List<BasicShoppingBanner>> getBanners(Integer goodsId) {
		return new R(shoppingMallService.getBanners(goodsId));
	}

	/**
	 * 获取推荐商品
	 *
	 * @return com.shycloud.mido.common.core.util.R
	 * @author xiaoxing.yu
	 * @date 3/5/21 9:29 AM
	 */
	@GetMapping("getRecommend")
	@ApiOperation(value = "热门推荐/谱库大全 - 获取推荐商品/曲集", tags = "后台商城 banner 设置接口")
	@ApiOperationSupport(order = 6)
	@ApiImplicitParam(name = "type", value = "1 曲集 2 商品 不传则曲集+商品", paramType = "query", dataType = "int")
	public R getRecommend(Integer type) {
		return new R(shoppingMallService.getRecommend(type));
	}

}
